package com.xiao.sulingwallet.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiao.sulingpublic.utils.PageUtils;
import com.xiao.sulingpublic.utils.R;
import com.xiao.sulingwallet.entity.TradeStateEntity;
import com.xiao.sulingwallet.service.TradeStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 交易信息表
 *
 * @author xiao
 * @email 1322127758@qq.com
 * @date 2022-03-30 17:57:48
 */
@RestController
@RequestMapping("sulingwallet/tradestate")
public class TradeStateController {
    @Autowired
    private TradeStateService tradeStateService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("sulingwallet:tradestate:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tradeStateService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{trsId}")
    //@RequiresPermissions("sulingwallet:tradestate:info")
    public R info(@PathVariable("trsId") Long trsId){
		TradeStateEntity tradeState = tradeStateService.getById(trsId);

        return R.ok().put("tradeState", tradeState);
    }

    /**
     * 通过用户号获取数据
     */
    @RequestMapping("/info/balance")
    public R getBalance(@RequestParam("userName")String userName){
        QueryWrapper<TradeStateEntity> queryWrapper = new QueryWrapper<TradeStateEntity>().eq("trs_member_id", userName).orderByDesc("trs_id");
        List<TradeStateEntity> list = tradeStateService.list(queryWrapper);
//select * from mxqg_trade_state order by trs_id desc limit 1,2
        return R.ok().put("tradeStates",list);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("sulingwallet:tradestate:save")
    public R save(@RequestBody TradeStateEntity tradeState){
		tradeStateService.save(tradeState);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("sulingwallet:tradestate:update")
    public R update(@RequestBody TradeStateEntity tradeState){
		tradeStateService.updateById(tradeState);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("sulingwallet:tradestate:delete")
    public R delete(@RequestBody Long[] trsIds){
		tradeStateService.removeByIds(Arrays.asList(trsIds));

        return R.ok();
    }

}
